Component({
  properties: {
    // 初始模式：dineIn-堂食，takeaway-外卖
    initialMode: {
      type: String,
      value: 'dineIn'
    },
    // 门店名称
    storeName: {
      type: String,
      value: '优选门店'
    },
    // 用户信息
    userInfo: {
      type: Object,
      value: {
        name: '张先生',
        phone: '138****1234',
        address: '北京市海淀区中关村南大街5号北京理工大学中心教学楼'
      }
    },
    // 初始地址展开状态
    initialAddressExpanded: {
      type: Boolean,
      value: false
    }
  },

  data: {
    deliveryMode: 'dineIn', // 当前模式
    isAddressExpanded: false // 地址是否展开
  },

  lifetimes: {
    attached: function() {
      // 组件实例进入页面节点树时执行
      this.setData({
        deliveryMode: this.properties.initialMode,
        isAddressExpanded: this.properties.initialAddressExpanded
      });
    }
  },

  methods: {
    // 切换堂食/外卖模式
    switchMode: function(e) {
      const mode = e.currentTarget.dataset.mode;
      if (this.data.deliveryMode === mode) return;
      
      this.setData({
        deliveryMode: mode
      });
      
      // 触发模式切换事件
      this.triggerEvent('modechange', { mode });
    },

    // 选择门店
    onStoreSelect: function() {
      this.triggerEvent('storechange');
    },

    // 切换地址
    onAddressChange: function() {
      this.triggerEvent('addresschange');
    },
    
    // 切换地址展开状态
    toggleAddress: function() {
      this.setData({
        isAddressExpanded: !this.data.isAddressExpanded
      });
      
      // 触发地址展开状态变化事件
      this.triggerEvent('addresstoggle', { expanded: this.data.isAddressExpanded });
    }
  }
});